const express = require('express');
const ejs = require('ejs');
const path = require('path')
let app = express()

// 渲染页面模板设置
app.set('veiws', path.join(__dirname, 'views'))
app.set('view angine', 'html')
app.engine('.html', ejs.__express)

//设置静态文件
app.use(express.static(path.join(__dirname, 'public')))

app.get('/', (req, res) => {
    // res.writeHead(200, {
    //     'content-type': 'text/html; charset=utf-8'
    // })
    res.render('index.html')
})
app.get('/index', (req, res) => {
    // res.writeHead(200, {
    //     'content-type': 'text/html; charset=utf-8'
    // })
    res.render('index.html')
})
app.get('/login', (req, res) => {
    // res.writeHead(200, {
    //     'content-type': 'text/html; charset=utf-8'
    // })
    res.render('login.html')
})
app.get('/resgiter', (req, res) => {
    res.render('resgiter.html')
})
app.get('/baseproduct', (req, res) => {
    res.render('baseproduct.html')
})
app.get('/addproduction', (req, res) => {
    res.render('addproduction.html')
})
app.get('/financial', (req, res) => {
    res.render('financial.html')
})
app.get('/order', (req, res) => {
    res.render('order.html')
});
app.get('/orderlist', (req, res) => {
    res.render('orderlist.html')
})
app.get('/orderlist', (req, res) => {
    res.render('orderlist.html')
})
app.get('/stock', (req, res) => {
    res.render('stock.html')
})
app.use((req, res) => {
    res.status(404).send('<h1>404,您访问的资源不存在！</h1>');
})
app.use((err, req, res) => {
    if (err) {
        res.status(500).send('<h1>500，服务器出错！</h1>');
    }
})
app.listen(5000, () => {
    console.log('服务器创建成功')
})